package com.zwj.pattern;

/**
 * @Author: Zwj
 * @Date: 2022/10/23 15:52
 */
public class ChainPatternDemo {

    //组装责任链
    private static AbstractLogger getChainOfLoggers(){
        AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR);
        AbstractLogger fileLogger = new FileLogger(AbstractLogger.DEBUG);
        AbstractLogger consoleLogger = new ConsoleLogger(AbstractLogger.INFO);
        errorLogger.setNextLogger(fileLogger);
        fileLogger.setNextLogger(consoleLogger);
        return errorLogger;
    }

    public static void main(String[] args) {
        AbstractLogger loggerChain = getChainOfLoggers();
        System.err.println(loggerChain.level);
        /**
         *当前的logger的level为3，那么就交给下一个logger执行
         * 下一个logger的level为2，依旧不能执行，继续交给下一个logger执行，
         * 最后来到了ConsoleLogger
         */
        loggerChain.logMessage(AbstractLogger.INFO, "This is an information.");

    }
}